var tags = function() {

    return {
     
        /***** TAG *****/
        
        //add the tag to the database
        addTagClickHandler : function (cid, host, did, dbase) {
        	var input = document.getElementById("addTagInput" + cid);
       		var tag = input.value;
        	if ((tag == '') || (tag.match(/^\s+$/)) ) return;
        	
        	//update the ui with the new tag - input to the http request
        	//callback function used to add the ui
        	var cb =
        		function (resp) {
        			if (resp=="exists") return;
        			var tagList = document.getElementById("tagList" + cid);
        			tagList.innerHTML = tagList.innerHTML + resp;
        		}
        	
        	//insert into datastore
        	//then use callbakc to add to the UI
        	var uri = host + "/tags/add-tag.xqy?cid="+cid+"&host="+host+"&did="+did+"&dbase="+dbase+"&tag="+tag
        	httpRequest(uri, cb);
        }
        ,
     
        //delete the tag in the database
        deleteTagClickHandler : function (cid, host, did, dbase, tag) {
			//remove from datastore
        	var uri = host + "/tags/delete-tag.xqy?did="+did+"&dbase="+dbase+"&tag="+tag
        	httpRequest(uri);
        	
        	//update the ui by removing the tag
        	var tagElement = document.getElementById("tag"+cid+tag);
        	tagElement.parentNode.removeChild(tagElement);
        }          
    }
}();